package br.com.actionsystem.gdp.relatorio;

import br.com.actionsystem.gdp.util.Connect;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

public class FabricaRelatorio {

	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

	String s = "lib/reports/";

	public void geraRelatorio(Date inicio, Date fim) throws JRException,
			SQLException {
		Connection conn = Connect.getConection();

		Map parameters = new HashMap();
		parameters.put("SUBREPORT_DIR", s);
		parameters.put("inicio", df.format(inicio));
		parameters.put("fim", df.format(fim));

		JasperPrint jprint = JasperFillManager.fillReport(s
				+ "agrupamento_categoria.jasper", parameters, conn);

		JasperViewer.viewReport(jprint, false);

		Connect.close(conn);
	}

	public void geraRelatorioSemAgrupar(Date inicio, Date fim)
			throws JRException, SQLException {
		Connection conn = Connect.getConection();

		Map parameters = new HashMap();
		parameters.put("SUBREPORT_DIR", s);
		parameters.put("inicio", df.format(inicio));
		parameters.put("fim", df.format(fim));

		JasperPrint jprint = JasperFillManager.fillReport(s
				+ "receitas_despesas_passado.jasper", parameters, conn);

		JasperViewer.viewReport(jprint, false);

		Connect.close(conn);
	}

	public void geraRelatorioEstimativa(Date inicio, Date fim)
			throws JRException, SQLException {
		Connection conn = Connect.getConection();

		Map parameters = new HashMap();
		parameters.put("SUBREPORT_DIR", s);
		parameters.put("inicio", df.format(inicio));
		parameters.put("fim", df.format(fim));

		JasperPrint jprint = JasperFillManager.fillReport(s
				+ "estimativa.jasper", parameters, conn);

		JasperViewer.viewReport(jprint, false);

		Connect.close(conn);
	}

	public void geraRelatorioReservas() throws JRException, SQLException {
		Connection conn = Connect.getConection();

		Map parameters = new HashMap();
		JasperPrint jprint = JasperFillManager.fillReport(
				s + "reservas.jasper", parameters, conn);
		JasperViewer.viewReport(jprint, false);
		Connect.close(conn);
	}
}
